﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Animoso.Domain;
using Animoso.Domain.Data;
using NHibernate;
using NHibernate.Criterion;

namespace Animoso.Data
{
    public class EventRepository : BaseRepository<Event>, IEventRepository
    {
        public IList<Event> GetUpcomingEvents(DateTime fromDate, int numberOfEvents)
        {
            using (ISession session = SessionProvider.GetSession())
            {
                IList<Event> returnList = session.CreateCriteria(typeof (Event))
                    .Add(Expression.Ge("DateTime", fromDate))
                    .SetMaxResults(numberOfEvents)
                    .AddOrder(Order.Asc("DateTime"))
                    .List<Event>();

                return returnList ?? (new List<Event>());
            }
        }
    }
}
